//
//  WaggleView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/3/20.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class WaggleView: UIView {
    
    private let tip = UILabel(title: "", color: UIColor.red, size: 15, align: .center)
    
    public var resetTipText:String? {
        didSet {
            tip.text = resetTipText
        }
    }
    
    // 左右晃动
    public func shake() -> Void {
        let kfa = CAKeyframeAnimation()
        kfa.keyPath = "transform.translation.x"
        let s = 16
        kfa.values = [-s,0,s,0,-s,0,s,0]
        kfa.duration = 0.3
        kfa.repeatCount = 2
        kfa.isRemovedOnCompletion = true
        tip.layer.add(kfa, forKey: nil)
    }
    
    override func layoutSubviews() {
        tip.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
        addSubview(tip)
    }
    
}
